import { createStore } from 'vuex'

export default createStore({
  state: {
    // 状态管理数据
    members: [
      { name: '张三', avatar: require('@/views/img/1.png'), joinTime: '2023-05-10', role: '群主' },
      { name: '李四', avatar: require('@/views/img/3.png'), joinTime: '2023-05-12', role: '管理员' },
      { name: '王五', avatar: require('@/views/img/4.png'), joinTime: '2023-05-15' },
      { name: '赵六', avatar: require('@/views/img/5.png'), joinTime: '2023-05-20' },
      { name: '孙七', avatar: require('@/views/img/6.png'), joinTime: '2023-05-25' },
      { name: '周八', avatar: require('@/views/img/7.png'), joinTime: '2023-06-01' }
    ],
    groupInfo: {
      name: '金金铲铲群',
      memberCount: 6,
      createTime: '2023-05-01'
    }
  },
  mutations: {
    // 修改状态的方法
    addMember(state, member) {
      state.members.push(member)
    },
    updateGroupInfo(state, info) {
      state.groupInfo = { ...state.groupInfo, ...info }
    }
  },
  actions: {
    // 异步操作
    fetchMembers() {
      // 模拟API请求
      return new Promise((resolve) => {
        setTimeout(() => {
          // 实际项目中这里会调用API获取数据
          resolve()
        }, 500)
      })
    }
  },
  modules: {
    // 模块划分
  }
})